package com.sinoglobal.dumping.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import com.sinoglobal.dumping.R;

/**
 * Created by Administrator on 2016/1/15.
 */
public class Dumpling_QQWXShare {


    private final PopupWindow popupWindow;
    private final Button qq;
    private final Button wx;

    public Dumpling_QQWXShare(Context context) {
        View view = View.inflate(context, R.layout.dumpling_qq_wx_share, null);
        qq = (Button) view.findViewById(R.id.dumpling_share_qq);
        wx = (Button) view.findViewById(R.id.dumpling_share_wx);
        popupWindow = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    }

    public void onShare(View parentView, final Dumpling_ShareListener shareListener) {
        popupWindow.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);
        qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareListener.qqShare();
            }
        });
        wx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareListener.wxShare();
            }
        });
    }

    public void sharePopDismiss() {
        if (popupWindow.isShowing()) {
            popupWindow.dismiss();
        }
    }

    public interface Dumpling_ShareListener {
        void qqShare();

        void wxShare();
    }

}
